package me.zhengjie.repository;

import me.zhengjie.dto.sqlServer.UnbindingOrderDetail;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

public interface UnbindingOrderDetailRepository  extends JpaRepository<UnbindingOrderDetail, Integer>, JpaSpecificationExecutor<UnbindingOrderDetail> {

    UnbindingOrderDetail findUnbindingOrderDetailByPalletCode(String palletCode);

    List<UnbindingOrderDetail> findUnbindingOrderDetailsByUnbindingOrderCode(String orderCode);

    @Query("select pi from UnbindingOrderDetail pi where pi.palletCode=?1 and pi.unbindingOrderCode=?2 order by pi.id desc")
    List<UnbindingOrderDetail> findUnbindingOrderDetailsByUnbindingOrderCodeAndPalletCode(String palletCode,String orderCode);

    @Modifying
    @Transactional
    @Query("update UnbindingOrderDetail pi set pi.inCache=1 where pi.palletCode=?1")
    void inCache(String palletCode);
}
